import urllib.request
import urllib.parse

url = 'http://www.baidu.com/s?wd='

# 请求对象的定制为了解决反爬的第一种手段
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0'
}

# 将周杰伦变为Unicode编码
name = urllib.parse.quote("周杰伦")
# 请求对象的定制
url = url + name

# 对URL进行编码
url = urllib.parse.quote(url, safe=':/&=?')

request = urllib.request.Request(url=url, headers=headers)
# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

print(content)
